﻿using System;
using System.Collections.Generic;
using System.Text;
using MSNPSharp;
using MSNPSharp.Core;
using MSNPSharp.DataTransfer;

namespace QMIM
{
    public class MSNMain
    {
        private Messenger messenger = new Messenger();
        public MSNMain()
        {
            
            messenger.Credentials.ClientID = "PROD0119GSJUC$18";
            messenger.Credentials.ClientCode = "ILTXC!4IXB5FB*PX";
            RegEvents();
        }
        #region 注册事件
        private void RegEvents()
        {
            messenger.Nameserver.SignedIn += new EventHandler<EventArgs>(Nameserver_SignedIn);
            //messenger.Nameserver.SignedOff += new EventHandler<SignedOffEventArgs>(Nameserver_SignedOff);
        }
        

        public event EventHandler LoginFailed;

        private void OnLoginFailed(EventArgs e)
        {
            if (LoginFailed != null)
            {
                LoginFailed(this, e);
            }
        }

        public event EventHandler LoginSuccessed;
        private void OnLoginSuccess(EventArgs e)
        {
            if (LoginSuccessed != null)
            {
                LoginSuccessed(this, e);
            }

        }
        #endregion

        public void DoLogin(string account, string passwd)
        {
            MSNForm.messenger = messenger;
            messenger.Credentials.Account = account;
            messenger.Credentials.Password = passwd;
            Console.WriteLine("msn loging...");
            messenger.Connect();
        }

        private void Nameserver_SignedIn(object sender, EventArgs e)
        {
            Console.WriteLine("Nameserver_SignedIn...");
            OnLoginSuccess(e);
        }

        
     
    }
}
